<?php
session_start();
//include('modul/general.php');
//check_pass();
//baca_permisi(43);
//global $permisi,$cdivisi_kode;
////ctr_array($permisi);
//if($permisi["access"]=="tolak"){
//	header('Location:tengah.php');
//}

function cari_spt(){
    global $inp_par,$inp,$permisi,$cdivisi_kode;
	$inp_par[hari]=$inp_par[hari]==""?1:$inp_par[hari];
	$inp_par[bulan]=$inp_par[bulan]==""?date('n'):$inp_par[bulan];
	$inp_par[tahun]=$inp_par[tahun]==""?date('Y'):$inp_par[tahun];
	$inp_par[hari_]=$inp_par[hari_]==""?date('j'):$inp_par[hari_];
	$inp_par[bulan_]=$inp_par[bulan_]==""?date('n'):$inp_par[bulan_];
	$inp_par[tahun_]=$inp_par[tahun_]==""?date('Y'):$inp_par[tahun_];
        $inp_par[divisi_kode]= $inp_par[divisi_kode] == ""? $cdivisi_kode:$inp_par[divisi_kode];

	$txtout.="<table width=\"98%\" height=\"35\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
		<td height=\"5\" colspan=\"2\"><img src=\"../img/0.gif\" width=\"1\" height=\"10\"></td>
		</tr>
		<tr>
		<td width=\"15\" background=\"../img/bg-jdl-ppn.gif\">&nbsp;</td>
		<td height=\"25\" background=\"../img/bg-jdl-ppn.gif\"><img src=\"../img/jdl-lap-faktur-pajak-masukan.gif\" height=\"25\"></td>
		</tr>
		</table>
		<form name=\"form1\" method=\"post\" action=\"?\">
		<table border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"hitam\">
		<tr>
                <td>Buku :&nbsp;</td>
                <td>".combo_array("inp_par[buku]",array("-Pilih-","Sudah","Belum"),$inp_par[buku])."</td>
                <td>&nbsp;Bayar :&nbsp;</td>
                <td>".combo_array("inp_par[bayar]",array("-Pilih-","Sudah","Belum"),$inp_par[bayar])."</td>
                <td>&nbsp;Lapor :&nbsp;</td>
                <td>".combo_array("inp_par[lapor]",array("-Pilih-","Sudah","Belum"),$inp_par[lapor])."</td>
                <td>&nbsp;No Faktur :&nbsp;</td>
                <td><input name=\"inp_par[txtcari]\" type=\"text\" class=\"form1\" size=\"30\" value=\"$inp_par[txtcari]\"></td>
		<td>&nbsp;Periode :&nbsp;</td>
		<td> ".combo_tanggal("inp_par[hari]",$inp_par[hari],1,31)."".combo_bulan("inp_par[bulan]",$inp_par[bulan])."".combo_tanggal("inp_par[tahun]",$inp_par[tahun],2000,2015)." </td>
		<td>&nbsp;S/D :&nbsp;</td>
		<td> ".combo_tanggal("inp_par[hari_]",$inp_par[hari_],1,31)."".combo_bulan("inp_par[bulan_]",$inp_par[bulan_])."".combo_tanggal("inp_par[tahun_]",$inp_par[tahun_],2000,2015)." </td>
                    <td>&nbsp;<input type=submit name=\"go\" value=\"GO &raquo;\" class=\"tombolgo\"></td>
		</tr>
		</table>
		</form>
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"C6E6FF\" class=\"tabel1\">
		<tr class=\"tbltagihan\">
		<td width=\"14\"> <div align=\"center\">No</div></td>
                <td width=\"14\"> <div align=\"center\">Wilayah</div></td>
                <td width=\"14\"> <div align=\"center\">Proyek</div></td>
		<td width=\"125\"><div align=\"center\">No. Faktur</div></td>
                <td width=\"80\"><div align=\"center\">Tanggal</div></td>
		<td width=\"125\"><div align=\"center\">Nama Rekanan</div></td>
		<td><div align=\"center\">NPWP Rekanan</div></td>
                <td><div align=\"center\">Alamat Rekanan</div></td>
                <td><div align=\"center\">DPP</div></td>
                <td><div align=\"center\">PPN(10%)</div></td>
                <td><div align=\"center\">Bukti Pembukuan</div></td>
                <td><div align=\"center\">Bukti Pembayaran</div></td>
                <td><div align=\"center\">Lapor SPT Masa</div></td>
		</tr>";

            if ($cdivisi_kode=='KP'){
                $cond_divisi_kode = " a.divisi_kode!=''";
            }else{
                $divisi_wilayah = explode(".",$cdivisi_kode);
                $divisi_len = strlen($divisi_wilayah[0]);
                if ($cdivisi_kode==$divisi_wilayah[0]){
                    $cond_divisi_kode = " substr(a.divisi_kode,1,$divisi_len)='".$divisi_wilayah[0]."'";
                }else{
                    $cond_divisi_kode = " a.divisi_kode='".$cdivisi_kode."'";
                }
            }

//	$divisi=($inp_par[divisi_kode]=="-1" or $inp_par[divisi_kode]=="")?"":"and a.divisi_kode='$inp_par[divisi_kode]'";
	$periode="and tgl_faktur>='".$inp_par[tahun]."-".$inp_par[bulan]."-".$inp_par[hari]."' and tgl_faktur<='".$inp_par[tahun_]."-".$inp_par[bulan_]."-".$inp_par[hari_]."'";

        $SQLcari="select a.* from tbl_spt a where $cond_divisi_kode and a.no_faktur_pajak!=''";
//        $SQLcari = "select a.no_faktur_pajak,c.nama_leveransir,c.npwp_leveransir,a.bukti_pembayaran,d.nama_proyek,b.divisi_name from tbl_spt a
//                    JOIN tbl_divisi b ON (a.divisi_kode = b.divisi_kode)
//                    JOIN m_leveransir c ON (a.id_leveransir = c.id_leveransir)
//                    JOIN m_proyek d ON (a.id_proyek = d.id_proyek) where $cond_divisi_kode";
        $kata=strtolower(trim($inp_par[txtcari]));
	if($kata<>""){
                $sqlq = getRSq($SQLcari);
                $jmlField = pg_num_fields($sqlq);
                for ($x=0;$x<$jmlField;$x++){
                    $namaField = pg_field_name($sqlq, $x);
                    $cond .= "lower(CAST(".$namaField." as TEXT)) LIKE lower('%$kata%') OR ";
                }
                $sql_tambahan = substr($cond,0,strlen($cond)-3);
		$sql_tambahan = " and ($sql_tambahan)";
	}
        if ($inp_par[buku]=="Belum"){
            $SQLCombo .= " AND is_buku='N'";
        }else if($inp_par[buku]=="Sudah"){
            $SQLCombo .= " AND is_buku='Y'";
        }else{
            $SQLCombo .= "";
        }

        if ($inp_par[bayar]=="Belum"){
            $SQLCombo .= " AND is_bayar='N'";
        }else if($inp_par[bayar]=="Sudah"){
            $SQLCombo .= " AND is_bayar='Y'";
        }else{
            $SQLCombo .= "";
        }

        if ($inp_par[lapor]=="Belum"){
            $SQLCombo .= " AND is_lapor='N'";
        }else if($inp_par[lapor]=="Sudah"){
            $SQLCombo .= " AND is_lapor='Y'";
        }else{
            $SQLCombo .= "";
        }
//	$customer=sqlkearray("select id_leveransir,nama_leveransir from m_leveransir");
//        $divisi = $cdivisi_kode == "KP"?"":" and a.divisi_kode='$cdivisi_kode'";
        $sql="select a.* from tbl_spt a where $cond_divisi_kode and a.no_faktur_pajak!='' $periode $SQLCombo $sql_tambahan order by a.tgl_faktur asc ,a.no_faktur_pajak asc";
//        $sql = "select a.*,b.divisi_name,c.nama_leveransir,c.npwp_leveransir,c.alamat_leveransir,d.nama_proyek from tbl_spt a
//                 JOIN tbl_divisi b ON (a.divisi_kode = b.divisi_kode)
//                 JOIN m_leveransir c ON (a.id_leveransir = c.id_leveransir)
//                JOIN m_proyek d ON (a.id_proyek = d.id_proyek) where $cond_divisi_kode $periode $SQLCombo $sql_tambahan order by tgl_faktur asc ,no_faktur_pajak asc";
//	$sql="select * from tbl_spt where no_faktur_pajak!='' $periode ".divisi("and","divisi_kode")." $divisi $SQLCombo $sql_tambahan order by tgl_faktur asc ,no_faktur_pajak asc";
	$arr_tabel=definisi_halaman($sql);
	$result=$arr_tabel["res_sql"];
	$i=1+$inp_par[awalan]*$inp_par[jumlah_per_hal];
	while($r=pg_fetch_array($result)){
		$warna=$warna=="#E3F1FC"?"#F4FAFF":"#E3F1FC";
                if ($r[is_buku]=='N'||$r[is_bayar]=='N'||$r[is_lapor]=='N'){
                    $warna="#FF9999";
                }
		$sql1="select * from m_leveransir where id_leveransir='$r[id_leveransir]'";
		$res1=dbresult($sql1);
		$r1=pg_fetch_array($res1);
                $proyek = cari_nilai("select nama_proyek from m_proyek where id_proyek='$r[id_proyek]'");
                $wilayah = cari_nilai("select divisi_name from tbl_divisi where divisi_kode='$r[divisi_kode]'");

		$txtout.="<tr onmouseover=\"this.style.backgroundColor='#FDFFDD';\" style=\"background-color: $warna;\" onmouseout=\"this.style.backgroundColor='$warna';\">
			<td><div align=\"center\">$i</div></td>
                        <td>$wilayah</td>
                        <td>$proyek</td>
			<td>$r[no_faktur_pajak]</td>
                        <td>".date_view($r[tgl_faktur])."</div></td>
                        <td>$r1[nama_leveransir]</td>
                        <td>$r1[npwp_leveransir]</td>
                        <td>$r1[alamat_leveransir]</td>
                        <td><div align=\"right\">".format_mede($r[dpp])."</div></td>
			<td><div align=\"right\">".format_mede($r[ppn])."</div></td>
                        <td>$r[bukti_pembukuan]</td>
                        <td>$r[bukti_pembayaran]</td>
                        <td>$r[tanggal_lapor]</td>";

	$txtout.=" </div></td></tr>";
	$i++;
	}

	$txtout.="</table>
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tbltagihan\">
		<tr>
		<td height='30'><a class='subputih' title='Print Html' href=?inp_par[mode]=printer&inp_par[hari]=$inp_par[hari]&inp_par[bulan]=$inp_par[bulan]&inp_par[tahun]=$inp_par[tahun]&inp_par[hari_]=$inp_par[hari_]&inp_par[bulan_]=$inp_par[bulan_]&inp_par[tahun_]=$inp_par[tahun_]&inp_par[buku]=$inp_par[buku]&inp_par[bayar]=$inp_par[bayar]&inp_par[lapor]=$inp_par[lapor]&inp_par[cetak]=html&inp_par[cari]=$kata target=_blank>&nbsp;Print HTML&nbsp;</a>
                |<a class='subputih' title='Print Excel' href=printExcel.php?inp_par[hari]=$inp_par[hari]&inp_par[bulan]=$inp_par[bulan]&inp_par[tahun]=$inp_par[tahun]&inp_par[hari_]=$inp_par[hari_]&inp_par[bulan_]=$inp_par[bulan_]&inp_par[tahun_]=$inp_par[tahun_]&inp_par[buku]=$inp_par[buku]&inp_par[bayar]=$inp_par[bayar]&inp_par[lapor]=$inp_par[lapor]&inp_par[cetak]=excel&inp_par[cari]=$kata target=_blank>&nbsp;Print EXCEL</a>";
	$txtout.="</td>
		<td>$arr_tabel[tabel_halaman]</td>
		</tr>
		</table>";
	return $txtout;
}

function printer(){
    global $inp_par,$inp,$permisi,$cdivisi_kode;
        $inp_par[hari]=$inp_par[hari]==""?1:$inp_par[hari];
	$inp_par[bulan]=$inp_par[bulan]==""?date('n'):$inp_par[bulan];
	$inp_par[tahun]=$inp_par[tahun]==""?date('Y'):$inp_par[tahun];
	$inp_par[hari_]=$inp_par[hari_]==""?date('j'):$inp_par[hari_];
	$inp_par[bulan_]=$inp_par[bulan_]==""?date('n'):$inp_par[bulan_];
	$inp_par[tahun_]=$inp_par[tahun_]==""?date('Y'):$inp_par[tahun_];
// Validasi Akses Divisi
    if ($cdivisi_kode=='KP'){
          $cond_divisi_kode = " a.divisi_kode!=''";
    }else{
          $divisi_wilayah = explode(".",$cdivisi_kode);
          $divisi_len = strlen($divisi_wilayah[0]);
        if ($cdivisi_kode==$divisi_wilayah[0]){
              $cond_divisi_kode = " substr(a.divisi_kode,1,$divisi_len)='".$divisi_wilayah[0]."'";
        }else{
              $cond_divisi_kode = " a.divisi_kode='".$cdivisi_kode."'";
        }
    }

        if ($inp_par[buku]=="Belum"){
            $SQLCombo .= " AND is_buku='N'";
        }else if($inp_par[buku]=="Sudah"){
            $SQLCombo .= " AND is_buku='Y'";
        }else{
            $SQLCombo .= "";
        }

        if ($inp_par[bayar]=="Belum"){
            $SQLCombo .= " AND is_bayar='N'";
        }else if($inp_par[bayar]=="Sudah"){
            $SQLCombo .= " AND is_bayar='Y'";
        }else{
            $SQLCombo .= "";
        }

        if ($inp_par[lapor]=="Belum"){
            $SQLCombo .= " AND is_lapor='N'";
        }else if($inp_par[lapor]=="Sudah"){
            $SQLCombo .= " AND is_lapor='Y'";
        }else{
            $SQLCombo .= "";
        }

        $periode="and tgl_faktur>='".$inp_par[tahun]."-".$inp_par[bulan]."-".$inp_par[hari]."' and tgl_faktur<='".$inp_par[tahun_]."-".$inp_par[bulan_]."-".$inp_par[hari_]."'";
        $SQLcari="select a.* from tbl_spt a where $cond_divisi_kode and a.no_faktur_pajak!=''";
//        $SQLcari = "select a.no_faktur_pajak,c.nama_leveransir,c.npwp_leveransir,a.bukti_pembayaran,d.nama_proyek,b.divisi_name from tbl_spt a
//                    JOIN tbl_divisi b ON (a.divisi_kode = b.divisi_kode)
//                    JOIN m_leveransir c ON (a.id_leveransir = c.id_leveransir)
//                    JOIN m_proyek d ON (a.id_proyek = d.id_proyek) where $cond_divisi_kode";
        $kata=strtolower(trim($inp_par[cari]));
	if($kata<>""){
                $sqlq = getRSq($SQLcari);
                $jmlField = pg_num_fields($sqlq);
                for ($x=0;$x<$jmlField;$x++){
                    $namaField = pg_field_name($sqlq, $x);
                    $cond .= "lower(CAST(".$namaField." as TEXT)) LIKE lower('%$kata%') OR ";
                }
                $sql_tambahan = substr($cond,0,strlen($cond)-3);
		$sql_tambahan = " and ($sql_tambahan)";
	}
        $period = $inp_par[hari]."/".$inp_par[bulan]."/".$inp_par[tahun]." - ".$inp_par[hari_]."/".$inp_par[bulan_]."/".$inp_par[tahun_];

 //$rwilayah = getRS("SELECT divisi_name FROM tbl_divisi WHERE divisi_kode='".$cdivisi_kode."'");
 $rwilayah = getNameFromID("tbl_divisi","divisi_name","AND divisi_kode='".$cdivisi_kode."'");
                $txtout1 .="<link rel=\"stylesheet\" type=\"text/css\" media=\"print\" href=\"../css/print.css\"/>";
                $txtout1 .="<title>PRINT</title>";
                $txtout1 .="<form action='' method='post'>";
                $txtout .="<table width='900px' border='0' align='center' cellpadding='0' cellspacing='1'>";
                $txtout .="<tr>";
                $txtout .="<td colspan=13 class=huruf>PT. NINDYA KARYA";
                $txtout .="</td>";
                $txtout .="</tr>";
                $txtout .="<tr>";
                $txtout .="<td colspan=13 class=huruf>".$rwilayah."";
                $txtout .="</td>";
                $txtout .="</tr>";
                $txtout .="<tr>";
                $txtout .="<td colspan=13 class=huruf></font>";
                $txtout .="</td>";
                $txtout .="</tr>";
                $txtout .="<tr><td colspan=13><div align=center class=title>";
                $txtout .="<b>DAFTAR FAKTUR PAJAK</b>";
                $txtout .="</div></td></tr>";
                $txtout .="<tr><td colspan=13 class=huruf><div align=center class=huruf>";
                $txtout .="PERIODE : $period";
                $txtout .="</div></td></tr>";
                $txtout .="<tr>";
                $txtout .="<td colspan=13 height='2'>&nbsp;</font>";
                $txtout .="</td>";
                $txtout .="</tr>";
                
        //$sql10 = "SELECT DISTINCT divisi_kode FROM tbl_spt ".$cond_divisi_kode.$SQL1.$SQL2."";
        $sqlDivisi = "SELECT DISTINCT a.divisi_kode from tbl_spt a where $cond_divisi_kode $periode $SQLCombo $sql_tambahan";
//        $sqlDivisi = "SELECT DISTINCT a.divisi_kode from tbl_spt a
//              JOIN tbl_divisi b ON (a.divisi_kode = b.divisi_kode)
//              JOIN m_leveransir c ON (a.id_leveransir = c.id_leveransir)
//                JOIN m_proyek d ON (a.id_proyek = d.id_proyek) where $cond_divisi_kode $periode $SQLCombo $sql_tambahan";
        $result1 = getRSq($sqlDivisi);
        $jmltotdpp = 0;
        $jmltotppn = 0;
        while($rs1=pg_fetch_array($result1)){
        $nama_divisi = getNameFromID("tbl_divisi","divisi_name","AND divisi_kode='".trim($rs1['divisi_kode'])."'");
        $txtout .="<tr bgcolor=#FFFFFF height=25>
                <td colspan='8' class=\"huruftot\">&nbsp;".$nama_divisi."</td>
                </tr>";
        $txtout .="<tr>";
                $txtout .="<td height='25' width='2%' class=\"b_kiri b_atas b_bawah huruf5\">NO</td>";
//                $txtout .="<td width='8%' class=\"b_kiri b_atas b_bawah huruf5\"><strong>WILAYAH</strong></td>";
                $txtout .="<td width='8%' class=\"b_kiri b_atas b_bawah huruf5\"><strong>NO F. PAJAK</strong></td>";
                $txtout .="<td width='10%' class=\"b_kiri b_atas b_bawah huruf5\"><strong>TGL F. PAJAK</strong></td>";
                $txtout .="<td width='14%' class=\"b_kiri b_atas b_bawah huruf5\"><strong>NAMA REKANAN</strong></td>";
                $txtout .="<td width='12%' class=\"b_kiri b_atas b_bawah huruf5\"><strong>NPWP REKANAN</strong></td>";
                $txtout .="<td width='20%' class=\"b_kiri b_atas b_bawah huruf5\"><strong>ALAMAT REKANAN</strong></td>";
                $txtout .="<td width='10%' class=\"b_kiri b_atas b_bawah huruf5\"><strong>DPP</strong></td>";
                $txtout .="<td width='10%' class=\"b_kiri b_kanan b_atas b_bawah huruf5\"><strong>PPN(10%)</strong></td>";
                $txtout .="</tr>";
        $sqlProyek = "SELECT DISTINCT a.id_proyek from tbl_spt a where $cond_divisi_kode and a.divisi_kode='$rs1[divisi_kode]' $periode $SQLCombo $sql_tambahan";
//        $sqlProyek = "SELECT DISTINCT a.id_proyek from tbl_spt a
//              JOIN tbl_divisi b ON (a.divisi_kode = b.divisi_kode)
//              JOIN m_leveransir c ON (a.id_leveransir = c.id_leveransir)
//                JOIN m_proyek d ON (a.id_proyek = d.id_proyek) where $cond_divisi_kode and a.divisi_kode='$rs1[divisi_kode]' $periode $SQLCombo $sql_tambahan";
        $resultP = getRSq($sqlProyek);
        $totdpp = 0;
        $totppn = 0;
        while($rsP=pg_fetch_array($resultP)){
        $sql="select a.* from tbl_spt a where $cond_divisi_kode and a.no_faktur_pajak!='' and a.divisi_kode='$rs1[divisi_kode]' $periode $SQLCombo $sql_tambahan and a.id_proyek='$rsP[id_proyek]'";
//        $sql = "select a.*,b.divisi_name,c.nama_leveransir,c.npwp_leveransir,c.alamat_leveransir,d.nama_proyek from tbl_spt a
//                 JOIN tbl_divisi b ON (a.divisi_kode = b.divisi_kode)
//                 JOIN m_leveransir c ON (a.id_leveransir = c.id_leveransir)
//                JOIN m_proyek d ON (a.id_proyek = d.id_proyek) where $cond_divisi_kode and a.divisi_kode='$rs1[divisi_kode]' $periode $SQLCombo $sql_tambahan and a.id_proyek='$rsP[id_proyek]' order by tgl_faktur asc ,no_faktur_pajak asc";
        $result = getRSq($sql);
        $no = 0;
        $warna = '#FFFFFF';
        
        $nama_proyek = getNameFromID("m_proyek","nama_proyek","AND id_proyek='".trim($rsP['id_proyek'])."'");
        $txtout .="<tr bgcolor=#FFFFFF height=25>
                <td colspan='8' class=\"b_kiri b_kanan b_bawah huruf4\">&nbsp;PROYEK :&nbsp;".$nama_proyek."</td>
                </tr>";
        $dpp=0;
        $ppn=0;
	while($r=pg_fetch_array($result)){
            $no++;
            if ($warna == '#FFFFFF'){
                $warna = '#E8EFFF';
            }else{
                $warna = '#FFFFFF';
            }
            if ($r['is_buku']=='N' && $r['is_bayar']=='N'){
                $warna = 'red';
            }
            $rsL1 = getRS("SELECT * FROM m_leveransir WHERE id_leveransir!='' AND id_leveransir='".trim($r['id_leveransir'])."'");
            if ($rsL1!=""){
                $NamaLeveransir1 = $rsL1['nama_leveransir'];
                $NPWPLeveransir1 = $rsL1['npwp_leveransir'];
                $AlamatLeveransir1 = $rsL1['alamat_leveransir'];
            }
            
            
        $txtout .="<tr bgcolor=#FFFFFF height=25>
            <td width='2%' class=\"b_kiri huruf4\">&nbsp;&nbsp;".$no."</td>
            <td width='8%' class=\"b_kiri huruf4\">&nbsp;".$r['no_faktur_pajak']."</td>
            <td width='10%' class=\"b_kiri huruf4\">&nbsp;".$r['tgl_faktur']."</td>
            <td width='14%' class=\"b_kiri huruf4\">&nbsp;".$NamaLeveransir1."</td>
            <td width='12%' class=\"b_kiri huruf4\">&nbsp;".$NPWPLeveransir1."</td>
            <td width='20%' class=\"b_kiri huruf4\">&nbsp;".$AlamatLeveransir1."</td>
            <td width='10%' align='right' class=\"b_kiri huruf4\">".number_format($r['dpp'])."&nbsp;</td>
            <td width='10%' align='right' class=\"b_kiri b_kanan huruf4\">".number_format($r['ppn'])."&nbsp;</td>
            </tr>
            ";
        $dpp +=$r['dpp'];
        $ppn +=$r['ppn'];
        }
        $txtout .="<tr height=25>
                    <td align='left' colspan='6' class=\"b_kiri b_atas b_bawah huruftot\">&nbsp;TOTAL PROYEK $nama_proyek</td>
                    <td align='right' class=\"b_kiri b_atas b_bawah huruftot\">".number_format($dpp)."&nbsp;</td>
                    <td align='right' class=\"b_kiri b_kanan b_atas b_bawah huruftot\">".number_format($ppn)."&nbsp;</td>
                    </tr>
                    ";
        $totdpp +=$dpp;
        $totppn +=$ppn;
    }
    if ($totdpp!=0 || $totppn!=0){
        $txtout .="<tr height=25>
                    <td align='left' colspan='6' class=\"b_kiri b_bawah huruftot\">&nbsp;TOTAL $nama_divisi</td>
                    <td align='right' class=\"b_kiri b_bawah huruftot\">".number_format($totdpp)."&nbsp;</td>
                    <td align='right' class=\"b_kiri b_kanan b_bawah huruftot\">".number_format($totppn)."&nbsp;</td>
                    </tr>
                    ";
        }
        $jmltotdpp +=$totdpp;
        $jmltotppn +=$totppn;
        }
        if ($jmltotdpp!=0 || $jmltotppn!=0){
        $txtout .="<tr height=25>
                    <td align='left' colspan='6' class=\"b_kiri b_bawah huruftot\">&nbsp;TOTAL</td>
                    <td align='right' class=\"b_kiri b_bawah huruftot\">".number_format($jmltotdpp)."&nbsp;</td>
                    <td align='right' class=\"b_kiri b_kanan b_bawah huruftot\">".number_format($jmltotppn)."&nbsp;</td>
                    </tr>
                    ";
        }
        
//                $txtout .="<tr>
//			<td colspan='13' class=\"b_atas\">&nbsp;</td>
//                        </tr>";
		$txtout2 .="<br>
			<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\" >
			<tr>
			<td width='50%'><div align=\"right\" id=\"noDisplay\"><a href=\"javascript:window.print()\" class=\"calender\" style=\"text-decoration:none\">PRINT</a>&nbsp;</div></td>
			<td width='50%'><div id=\"noDisplay\">&nbsp;<a href=\"javascript:this.close()\" class=\"calender\" style=\"text-decoration:none\">CLOSE</a></div></td>
			</tr>
			</table>";
        $txtout3 .="</table>";
        $txtout4 .="</form>";
        $txtoutTot = $txtout1.$txtout.$txtout2.$txtout3.$txtout4;
        if ($inp_par[cetak]=='html'){
            return $txtoutTot;
        }
//        if ($mdprint=='pdf'){
//
//            require('pdf-in-php/html2fpdf/html2fpdf.php');
//            $pdf = new HTML2FPDF('L','mm','A3');
//            $pdf->AddPage();
//            $pdf->SetFont('Arial','B','12');
//            $txtoutPDF = $txtout.$txtout3;
//            $strContent = $txtoutPDF;
//            $pdf->WriteHTML($strContent);
//            $pdf->Output();
//        }
}

function generate_form($inp_par){
	global $inp;
	switch($inp_par[mode]){
		case "printer":
			$txtout.=printer();
		break;
		case "cari":
			$txtout.=cari_spt();
		break;
		default:
		$txtout.=cari_spt();
		break;
	}
	return $txtout;
}
?>
